-
-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rich text #2321
Rich text #2321
Conversation
Compile Times benchmarkNote, that these numbers may fluctuate on the CI servers, so take them with a grain of salt. All benchmark results are based on the mean time and negative percent mean faster than the base branch. Note, that GLMakie + WGLMakie run on an emulated GPU, so the runtime benchmark is much slower. Results are from running: using_time = @ctime using Backend
# Compile time
create_time = @ctime fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @ctime Makie.colorbuffer(display(fig))
# Runtime
create_time = @benchmark fig = scatter(1:4; color=1:4, colormap=:turbo, markersize=20, visible=true)
display_time = @benchmark Makie.colorbuffer(display(fig))
|
Missing reference imagesFound 1 new images without existing references. |
Missing reference imagesFound 1 new images without existing references. |
Can I suggest that instead of specifying bold etc fonts directly, we allow the user to simply pass a What I thought of was something like this: ...
font = "TeX Gyre Heros Makie"
# or
texgyre_family = FontFamily("TeX Gyre Heros Makie"; semibold = "Calibri") # for example, can set any font
...
font = texgyre_family This way, one could simply specify via the x-label formatter if the font should be bold etc. |
That's kind of how it works in this PR, no? fonts = Dict(
:regular => "Makie Regular",
:bold => "Makie Bold",
:semibold => "Calibri" # whatever
)
set_theme!(fonts = fonts)
text(1, 2, text = "hi", font = :semibold) |
Hmm, that does make sense. Basically what I wanted to make sure of was that (a) people can still set For (a) it looks like you can already do this, but (b) would basically just require an easier way to set the font family. One way we could do this is by somehow auto-converting when a String is given to |
I personally really dislike choosing fonts not by name but by abstract attributes. I know that there are some fonts that only have the regular, italic, bold, bold italic combination, but I tend to want to use fonts that have like 30 variants. That's why I wanted to make it easy to pick exactly the fonts you want (by name) and not make it convenient to do something that is often correct but bites you in all other cases. That's matplotlib's system to me, for example. I once dove down all the way into their font handling code just to understand why my font theme didn't resolve correctly, and it was all heuristics about font weights and stuff. The family plus style name is actually really easy to do find out and use in my opinion, so I stuck with that in Makie. What you can do on the other hand, is add a convenience function like |
So I was looking into this, and ended up diving a bit into Fontconfig/Freetype interaction. Ended up writing a basic integration which allows us to use Fontconfig. Will make that a PR to this one in the next couple of days. Good news: figured out how to use Fontconfig with Makie, meaning that we can use that as a somewhat better search engine... This raises another edge case which should be solved before this gets merged - how should we handle font names? Some fonts have them labelled as oblique, instead of italic, which is fair enough but liable to get users confused. Additionally, most style names in fonts come with spaces - meaning that we would either have to force the users to use the exact syntax of the font, or create some sort of lookup engine for the most common ones (possibly both!) P.S. With this, we can actually use single-file fonts with multiple faces! If you tried "Helvetica Bold" as a font now, it wouldn't work, since we currently have no way of distinguishing between multiple fonts in a single file in Makie. |
I did already think a lot about these problems years back when I rewrote the font finding in FreeTypeAbstraction, maybe have a look at the closed PRs there, there might still be bits of discussion. Anyway, I settled on using font names with a shortest match policy, and that seems to have worked well so far. I wouldn't want you to spend tons of time on getting fontconfig to work if that doesn't clearly improve on a problem we currently have. And so far I haven't seen that problem, so if you want to go forward, probably best to collect problematic use cases first and present them here for further discussion :) |
Well, the problem as I see it is the following:
Similar things apply to basically any font which a user downloads as a single file, which is somewhat prevalent on common font sites. I just put up #2400 which implements this interface - after looking at the Fontconfig docs, it was surprisingly easy. Do give it a look! |
Missing reference imagesFound 1 new images without existing references. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great to have this!! :)
From what I can tell, this is not breaking, right?
If it is, we should tag current master as a patch/bugfix release first.
Apart from this, I think this is ready to be merged!
We should not forget to add the new refimage, though!
The description notes two ways in which the PR is breaking, so it should go into a minor release. I was thinking to bundle it with the fontsize refactor. |
Missing reference imagesFound 1 new images without existing references. |
It would be nice to open a separate PR that contains the hyphen/minus change, as suggested above. Matplotlib does this, and it seems like all professional mathematical typesetting (e.g. LaTeX or CMOS) uses a different (wider) glyph for the minus sign than for a hyphen. It's quite painful to ask users to do this manually. |
Description
Adds a rich text data structure which allows to plot strings with colors, subscripts, superscripts, different fonts and fontsizes specified internally. Also adds the ability to specify fonts by symbols such as
:regular
and passing a top-level dictionary that resolves these symbols.This PR is breaking in two ways:
Figure(..., font = xyz)
will not have the expected effect anymore, because all theBlock
s likeAxis
which previously inherited their fonts from this field do not do this anymore. Instead, they are set to:regular
or:bold
. The new way to change fonts should therefore beFigure(..., fonts = (; regular = xyz, bold = abc))
. The benefit of this is obviously that you can theme more than one font category, before you would have had to change Axis3 title, Axis title, Legend title all separately if you didn't want the bold font used there.Examples:
Using rich superscripts also fixes the mismatching exponents because TeX Gyre Heros only had superscripts 1 to 3:
Before:
After:
Delete options that do not apply:
Checklist